﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using DuckEntities;
using DuckClient.Helpers;
using System.Collections.Generic;

namespace DuckClient.ViewModel
{
    public class DuckPageViewModel: ViewModelBase
    {
        private DuckViewModel duckViewModel;
        private ChildWindow childWindow;

        public DuckPageViewModel(List<DUCK> ducks, DuckViewModel dvm, ChildWindow cw)
        {
            this.duckViewModel = dvm;
            DucksResult = ducks;
            this.childWindow = cw;
            this.OKButton = new RelayCommand(OkButtonPressed);
            this.CancelButton = new RelayCommand(CancelButtonPressed);
        }

        private List<DUCK> result;

        public List<DUCK> DucksResult
        {
            get { return result; }
            set
            {
                if (result != value)
                {
                    result = value;
                    RaisePropertyChanged("DucksResult");
                }
            }
        }

        private DUCK selectedDuck;

        public DUCK SelectedDuck
        {
            get { return selectedDuck; }
            set
            {
                if (selectedDuck != value)
                {
                    selectedDuck = value;
                    RaisePropertyChanged("SelectedDuck");
                }
            }
        }

        public RelayCommand OKButton { get; set; }

        public RelayCommand CancelButton { get; set; }

        private void OkButtonPressed()
        {
            duckViewModel.SelectedDuck = this.SelectedDuck;
            this.childWindow.DialogResult = true;
        }

        private void CancelButtonPressed()
        {
            this.childWindow.DialogResult = false;
        }
    }
}
